import tkinter as tk
from tkinter import *
from tkinter import ttk

from milvus_demo.milvus_demo_remote import drop_connection, create_connection, insert_data,  query_milvus

# 创建主窗口
root = tk.Tk()
root.title("Milvus Demo UI")
root.geometry("600x400")

# 创建按钮框架
button_frame = ttk.Frame(root)
button_frame.pack(pady=10)

def button_drop_connection():
    """"""
    drop_connection()
    # 在多行文本框中增加信息 '删除集合成功'
    text_box.insert(tk.END, "删除集合成功\n")

def button_create_connection():
    """"""
    create_connection()
    text_box.insert(tk.END, "创建集合成功\n")


def button_insert_data():
    """"""
    insert_data()
    text_box.insert(tk.END, "插入数据成功\n")

def button_query():
    """"""
    query="When was artificial intelligence founded"
    res=query_milvus(query)
    text_box.insert(tk.END, f"{str(res)}\n")

# 添加创建集合按钮
create_collection_button = ttk.Button(button_frame, text="删除集合", command=lambda: button_drop_connection())
create_collection_button.pack(side=LEFT)

create_collection_button = ttk.Button(button_frame, text="创建集合", command=lambda: button_create_connection())
create_collection_button.pack(side=LEFT)

create_collection_button = ttk.Button(button_frame, text="插入数据", command=lambda: button_insert_data())
create_collection_button.pack(side=LEFT)

create_collection_button = ttk.Button(button_frame, text="查询", command=lambda: button_query())
create_collection_button.pack(side=LEFT)

# 创建框架
button_frame = ttk.Frame(root)
button_frame.pack(fill=X)
# 添加信息标签
info_label = ttk.Label(button_frame, text="信息", font=("TkDefaultFont", 10))
info_label.pack(side=LEFT)

create_collection_button = ttk.Button(button_frame, text="清除消息", command=lambda: text_box.option_clear())
create_collection_button.pack(side=RIGHT)

# 创建多行文本框
text_box = tk.Text(root, wrap=tk.WORD, height=15, width=70)
text_box.pack(pady=10)

# 运行主循环
root.mainloop()